/*
 * 统计模块业务统计出院js
 * @author 杨腊梅
 * 2016/1/20
 * 
 */
$('#bih_monthDate').val(new Date().Format('yyyy'));
$('#tcm_businessInHospital_eCharts').css('height',orange.detailPage.getHeight());
$('#tcm_businessInHospital_eCharts').css('width',orange.detailPage.getWidth());
$('#tcm_businessInHospital_grid').datagrid(
		{
			url:"d/inhostpital/table",
			queryParams:{
				orgGuid:$("#tcmcpdetail_guid").val(),
				year:$("#bih_monthDate").val()
			},
			singleSelect:true,
			rownumbers:true,
			columns:[[
			         {field:'orgName',title:'中医馆名称',width:'23%',sortable:true,halign:'center'},
			         {field:'amountNormal',title:"正常出院人次",width:'25%',sortable:true,halign:'center'},
			         {field:'amountDeath',title:"死亡出院人次",width:'25%',sortable:true,halign:'center'},
			         {field:'amountArrearage',title:"欠费出院人次",width:'25%',sortable:true,halign:'center'},	         
			         ]],
			pagination:true,
			sortable:true,
			sortName: 'tcm_name',
			sortOrder: 'asc'
		}
);
function tcm_businessInHospital_query(){
	$('#tcm_businessInHospital_grid').datagrid({
		url:"d/inhostpital/table",
		queryParams:{
			orgGuid:$("#tcmcpdetail_guid").val(),
			year:$("#bih_monthDate").val()
		}
	});
	initbusinessBaseChartData();
}

/*
 * 图表数据初始化
 */
var tcm_myChart = echarts.init($('#tcm_businessInHospital_eCharts')[0]);
var tcm_initData = [];
var tcm_serialData_normal = [];
var tcm_serialData_death = [];
var tcm_serialData_owe = [];
var tcm_xData = [];
initbusinessBaseChartData();
function initbusinessBaseChartData(){
	tcm_serialData_normal.length = 0;
	tcm_serialData_death.length = 0;
	tcm_serialData_owe.length = 0;
	tcm_xData.length = 0;
	$.ajax({
		url:"d/inhospital/chart",
		type:"get",
		data:{orgGuid:$("#tcmcpdetail_guid").val(),
			year:$("#bih_monthDate").val()},
		success:function(data){
			tcm_initData = JSON.parse(data)
			for(var i=0; i<tcm_initData.length; i++) {
				tcm_serialData_normal.push(tcm_initData[i].amountNormal);
				tcm_serialData_death.push(tcm_initData[i].amountDeath);
				tcm_serialData_owe.push(tcm_initData[i].amountArrearage);
				tcm_xData.push(tcm_initData[i].period);
			}
			debugger;
			tcm_myChart.clear;
			tcm_myChart = echarts.init($('#tcm_businessInHospital_eCharts')[0]);
			tcm_myChart.setOption(tcm_option);
		}
	});
}


/*
 * 设置图表格式
 */
tcm_option={
		grid:{
			show:false,
			bottom :'15%',
			top:'25%',
			height:'65%',
			width:'80%',
			left:'10%',
			right:'15%'
		},
		
		tooltip : {
			trigger : 'axis'
		},
		
		legend : {
			top : '8%',
			data : ['正常出院人次', '死亡出院人次', '欠费出院人次']
		},
		
		xAxis : [{
			type : 'category',
			boundaryGap : false,
			data : tcm_xData
		}],
		
		yAxis : [{
			type:'value'
		}],
		
		series : [
		  {
			  type : 'line',
			  name : "正常出院人次",
			  smooth : true,
			  data : tcm_serialData_normal
		  },
		  {
			  type : 'line',
			  name : "死亡出院人次",
			  smooth : true,
			  data : tcm_serialData_death
		  },
		  {
			  type : 'line',
			  name : "欠费出院人次",
			  smooth : true,
			  data : tcm_serialData_owe
		  }
		],
};

//使用刚指定的配置项和数据显示图表
tcm_myChart.setOption(tcm_option);